package testJdk.timer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @ClassName : learn_jdk.timer.TimerTest
 * @Description : 类描述
 * Created by cyd on 2021-03-26 00:03:10
 */
public class TimerTest {
    /**
     * 测试timer
     */
    public static void main(String[] args) {
        Timer timer = new Timer();
        long l = System.currentTimeMillis();
        Date date = new Date(l);
        String format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
        System.out.println(format);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println(System.currentTimeMillis());
            }
        }, 1000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello");
                timer.cancel();
            }
        }, 1000);


    }
}
